package com.magicode.common.service.impl;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;

import com.magicode.common.assist.PropertiesUtil;
import com.magicode.common.service.IPathService;

@Service("pathService")
public class PathServiceImpl implements IPathService {

	@Override
	public String getContextPath(HttpServletRequest request) {
		String contextPath = request.getContextPath();  
		return contextPath;
	}
	
	@Override
	public String getWebAbsolutePath(HttpServletRequest request) {
		String contextPath = this.getContextPath(request);
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+contextPath;
		return basePath;
	}

	@Override
	public String getImagesRlativePath(HttpServletRequest request) {
		String mainPicUrl = "" ;
        mainPicUrl = this.getContextPath(request) + "/" + PropertiesUtil.parseStr( "images_upload_path");
		return mainPicUrl;
	}
	
	@Override
	public String getImagesRlativePathApplication(String contextPath) {
		String mainPicUrl = "" ;
        mainPicUrl = contextPath + "/" + PropertiesUtil.parseStr( "images_upload_path");
		return mainPicUrl;
	}

}
